﻿
#include"list.h"
#include"other.hpp"

#include<ctime>

namespace linhui
{
	struct A
	{
		int a;
		int b;
	};
	void test1()
	{
		/*list<int> li;
		li.push_back(9);
		li.push_back(9);
		li.push_back(9);
		li.push_back(9);
		li.push_back(9);*/
		list<A> la;
		la.push_back(A());
		la.push_back(A());
		la.push_back(A());
		la.push_back(A());
		list<A>::iterator it = la.begin();
		while (it != la.end())
		{
			cout << it->a << " " << it->b << " ";
			//++it;
			it++;
		}
		cout << endl;
		/*const list<int> li;
		li.push_back(4);
		li.push_back(7);
		li.push_back(3);
		li.push_back(6);
		li.push_back(2);
		list<int>::iterator it = li.cbegin();
		while (it != li.cend())
		{
			*it = 9;
			cout << *it << " ";
			++it;
		}*/
		/*for (auto au : li)
		{
			cout << au <<" ";
		}*/
		//printContainer(li);
	}
	void test2()
	{
		list<int> li;
		li.push_back(9);
		li.push_back(4);
		li.push_back(3);
		li.push_back(9);
		li.push_back(5);
		li.push_back(5);
		li.push_back(5);
		li.erase(li.begin());
		li.erase(li.begin());
		list<int>::const_iterator it = li.cbegin();
		while (it != li.cend())
		{
			//*it = 9;
			cout << *it << " ";
			++it;
		}
		cout << endl;
		//PrintContainer(li);
	}
	//删除所有偶数
	void test3()
	{
		list<int> li;
		li.push_back(1);
		li.push_back(2);
		li.push_back(2);
		li.push_back(3);
		li.push_back(4);
		li.push_back(5);
		li.push_back(6);
		li.push_back(6);
		list<int>::iterator it = li.begin();
		while (it != li.end())
		{
			/*if (*it % 2 == 0)
				it = li.erase(it);
			++it;*/
			if (*it % 2 == 0)
			{
				it = li.erase(it);
			}
			else
				it++;
		}
		PrintContainer(li);
	}
	//测试插入
	void test4()
	{
		list<int> li;
		li.insert(li.begin(), 1);
		li.insert(li.begin(), 1);
		PrintContainer(li);
		li.insert(li.begin(), 8);
		PrintContainer(li);

		li.clear();
	}
	//测试拷贝构造和赋值重载
	void test5()
	{
		list<int> li;
		li.push_back(1);
		li.push_back(2);
		li.push_back(2);
		li.push_back(3);
		li.push_back(4);
		PrintContainer(li);
		list<int> copy(li);
		PrintContainer(copy);
		list<int> copy1 = li;
		PrintContainer(copy1);
	}
	//测试initializer_list
	void test6()
	{
		//标准库里的
		std::list<double> li1{ 2.3,2.3,6.3,8.9,1.4 };
		PrintContainer(li1);

		//咱自己的
		list<double> li2{ 2.3,2.3,6.3,8.9,1.4 };
		PrintContainer(li2);
	}
}

int main()
{
	linhui::test6();
	//linhui::test5();
	//linhui::test4();
	//linhui::test3();
	//linhui::test2();
	//linhui::test1();
	cout << "good moring , world " << endl;
	//cout << "good evening , world "<<endl;
	return 0;
}





#ifdef U
//熟悉使用list
void test_std_list()
{
	//std::list<int> li;
	/*std::list<int> li1(5,7);
	std::list<int> li2(li1.begin(),li1.end());
	for (auto au : li)
	{
		std::cout << au << " ";
	}
	std::cout << std::endl;
	for (auto au : li1)
	{
		std::cout << au << " ";
	}
	std::cout << std::endl;
	for (auto au : li2)
	{
		std::cout << au << " ";
	}*/
	//std::cout << li.max_size();
	/*li.push_back(4);
	li.push_back(1);
	li.push_back(9);
	li.push_back(2);
	li.push_back(3);
	li.push_back(7);
	std::cout << li.front() << " \n";
	std::cout << li.back() << " \n";*/
}
namespace linhui
{
	void test_constructor()
	{
		list<int> v;
		v.push_back(9);
		v.push_back(7);
		v.push_back(3);
		v.push_back(6);
		v.push_back(4);
		v.push_back(5);
		list<int>::iterator it = v.begin();
		cout << endl;
		cout << *it << endl;
		while (it != v.end())
		{
			cout << *it << " ";
			//++it;
			it++;
		}
		cout << endl;
		
	}
}
void test_QuickSort()
{
	srand(time(0));
	vector<int> v;
	for (int i = 0; i < 20; i++)
	{
		v.push_back(rand()%100 );
	}
	for (auto& au : v)
	{
		std::cout << au << " ";
	}
	std::cout << "\n";
	QuickSort(v);
	for (auto& au : v)
	{
		std::cout << au <<" ";
	}
}
void test_InsertSort()
{
	srand(time(0));
	vector<int> v;
	//for (int i = 0; i < 30; i++)
	for (int i = 0; i < 10; i++)
	{
		v.push_back(rand() % 100);
	}
	for (auto& au : v)
	{
		std::cout << au << " ";
	}
	std::cout << "\n";
	//InsertSort(v);
	//ShellSort1(v);
	//ShellSort2(v);
	SelectSort(v);
	for (auto& au : v)
	{
		std::cout << au << " ";
	}
}
int main()
{
	//test_InsertSort();
	//test_QuickSort();
	linhui::test_constructor();
	//test_std_list();

	return 0;
}

#endif